#!/bin/bash

#FROM openjdk:8-jdk
#FROM arm64v8/openjdk:8
#FROM arm32v7/openjdk:8

# judgement build parameter
if [ ! -n "$1" ] ;then
    echo "Use default openjdk-8"
    jdkVer="openjdk:8-jdk"
else
    echo "Set JDK to $1"
    jdkVer=$1
fi

version=$2

# login
#sudo docker login --username=brucelee188 registry.cn-hangzhou.aliyuncs.com

# forbit error Error saving credentials: error storing credentials - err: exit status 1, out: `Cannot autolaunch D-Bus without X11 $DISPLAY`
# $ vi ~/.docker/config.json
#{
#	"auths": {
#		"registry.cn-hangzhou.aliyuncs.com": {
#			"auth": "YnJ1Y2VsZWUxODg6NzE0MTU5MzdBYg=="
#		}
#	}
#}
docker login --username=brucelee188 registry.cn-hangzhou.aliyuncs.com
# 71**Ab

# delete all images
docker rmi  -f `docker images|grep ruoyi`

# build images
cd ruoyi-visual/ruoyi-monitor
docker build -t registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-visual-monitor-arm:${version} -f Dockerfile --build-arg jdkVer=${jdkVer} .

cd ../../
cd ruoyi-modules/ruoyi-system
docker build -t registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-system-arm:${version} -f Dockerfile --build-arg jdkVer=${jdkVer} .

cd ../../
cd ruoyi-modules/ruoyi-job
docker build -t registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-job-arm:${version} -f Dockerfile --build-arg jdkVer=${jdkVer} .

cd ../../
cd ruoyi-gateway
docker build -t registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-gateway-arm:${version} -f Dockerfile --build-arg jdkVer=${jdkVer} .

cd ../
cd ruoyi-modules/ruoyi-file
docker build -t registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-file-arm:${version} -f Dockerfile --build-arg jdkVer=${jdkVer} .

cd ../../
cd ruoyi-auth
docker build -t registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-auth-arm:${version} -f Dockerfile --build-arg jdkVer=${jdkVer} .


# pull images
docker push registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-visual-monitor-arm:${version}
docker push registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-system-arm:${version}
docker push registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-job-arm:${version}
docker push registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-gateway-arm:${version}
docker push registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-file-arm:${version}
docker push registry.cn-hangzhou.aliyuncs.com/neo_ruoyi/ruoyi-auth-arm:${version}

